import { Component, OnInit, Injector } from '@angular/core';
import { NgZorroPageBaseComponent } from '../../../core/ng-zorro-page-base-component/ng-zorro-page-base-component.component';
import { CityListComponent } from '../../school/cityList';
import { Router, ActivatedRoute, Params } from '@angular/router';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import {
  PagedResultDto, ClassInfoOutput, PagerSearchInput, HttpService, BaseComponentConfig,
  CustomNavigation, KeyValueOutput, SearchValue
} from '../../..';

@Component({
  selector: 'app-studentmanage',
  templateUrl: './studentmanage.component.html',
  styleUrls: ['./studentmanage.component.scss']
})
export class StudentmanageComponent implements OnInit {
  classid;
  allstudentdata = [];
  allChecked = false;
  indeterminate = true;
  smisVisible = false;
  delesh = {}; // 学生id
  name;
  isSpinning = false;

  constructor(injecter: Injector,
    private router: Router,
    private message: NzMessageService,
    private activatedRoute: ActivatedRoute,
    public http: HttpService) {
  }

  ngOnInit() {
    this.activatedRoute.queryParams.subscribe(
      data => this.classid = (data['classId']));

    this.http.get<any>(`StudentInfo/GetAllStudentInfoByClassInfo?cId=${this.classid}`).then(e => {
      this.allstudentdata = e;
      if (!this.allstudentdata[0]) {
        this.message.info('班级没有学生');
      }
    });
  }



  cancle() {
    this.allChecked = false;
  }
  async dstydent(id: string, name) {
    this.name = name;
    this.delesh = { "ClassInfoId": this.classid, "StudentId": id };
    this.smisVisible = false;
    await this.http.post<any>('ClassInfo/RemoveClassStudent', this.delesh).then(e => {
      this.allstudentdata = e;
    });
    this.delesh = [];
    await this.http.get<any>(`StudentInfo/GetAllStudentInfoByClassInfo?cId=${this.classid}`).then(e => {
      this.allstudentdata = e;
      if (!this.allstudentdata[0]) {
        this.message.info('班级没有学生');
      }
    });
    this.message.create('success', `移除成功`);
    // this.smisVisible = true;
  }

  async handleOksm(type: string) {
    this.smisVisible = false;
    await this.http.post<any>('ClassInfo/RemoveClassStudent', this.delesh).then(e => {
      this.allstudentdata = e;
    });
    this.delesh = [];
    await this.http.get<any>(`StudentInfo/GetAllStudentInfoByClassInfo?cId=${this.classid}`).then(e => {
      this.allstudentdata = e;
      if (!this.allstudentdata[0]) {
        this.message.info('班级没有学生');
      }
    });
    this.message.create(type, `移除成功`);


  }
  handleCancel() {
    this.smisVisible = false;
  }

}
